package com.bygf.curve.demo;

import com.bygf.curve.axis.TimeAxis;
import com.bygf.curve.Curve;
import com.bygf.curve.TimeCurve;
import com.bygf.curve.XYCurve;
import com.bygf.curve.panel.ChartPanel;
import com.bygf.curve.utils.ToolTipFormat;
import java.awt.Color;
import java.awt.Font;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *
 * @author sunyupei
 */
public class TimeCurveDemo1 extends javax.swing.JPanel {

    ChartPanel chartPanel = new ChartPanel();

    /**
     * Creates new form XYCurve
     */
    public TimeCurveDemo1() {
        initComponents();
        chartPanel = new ChartPanel("时间曲线演示", "time", "y", "", false);
        chartPanel.setBounds(0, 0, this.getWidth(), this.getHeight());
        TimeAxis timeAxis = new TimeAxis(chartPanel, "time");
        Date d1 = new Date(new Date().getTime() - 1000l * 60 * 60);
        Date d2 = new Date();
        timeAxis.setStartDate(d1);
        timeAxis.setEndDate(d2);
        chartPanel.setXAxis(timeAxis);
        chartPanel.getYAxis().setStartValue(0);
        chartPanel.getYAxis().setEndValue(100);
        chartPanel.getTitlePanel().setTitleFont(new Font("宋体", Font.BOLD, 26));
        List<Curve> curveList = new ArrayList<>();
        TimeCurve curve = new TimeCurve("时间曲线");
        int x = 0;
        for (long i = d1.getTime(); i < d2.getTime(); i += 1000) {
            curve.addItem(new Date(i), Math.sin(Math.toRadians(x++)) * 25 + 50);
        }
        curveList.add(curve);
        chartPanel.getCurvePanel().setCurveList(curveList);
        curve.setToolTipFormat(new ToolTipFormat("{0}:{1},{2}", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), null));
        this.add(chartPanel);
    }

    @Override
    public void setBounds(int x, int y, int width, int height) {
        super.setBounds(x, y, width, height);
        chartPanel.setBounds(0, 0, this.getWidth(), this.getHeight());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 547, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 387, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
